package org.kunlong.netix.processor.standardprocessor;

import java.io.IOException;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;

import org.kunlong.netix.exception.LifeCycleException;
import org.kunlong.netix.processor.Processor;

public class StandardProcessor implements Processor{
	//private boolean status=false;
	private static final int SIZE=8;
	private JobPool jobPool=new JobPool();
	private List<JobHandler> handlers=new ArrayList<JobHandler>();
	public void init() throws LifeCycleException {
		// TODO Auto-generated method stub
		//status=true;
		jobPool.init(SIZE);//init jobPool
		for(JobQueue jq:jobPool.getJobList()){
			handlers.add(new JobHandler(jq));//new handler
		}
	}

	public void start() throws LifeCycleException {
		// TODO Auto-generated method stub
		Thread[] threads=new Thread[SIZE];
		for(int i=0;i<SIZE;i++){
			threads[i]=new Thread(handlers.get(i));
			threads[i].start();
		}
	}
	
	public void stop() throws LifeCycleException {
		// TODO Auto-generated method stub

	}

	public void process(Socket s) throws IOException {
		// TODO Auto-generated method stub
		jobPool.addJob(new Job(s));
	}
}
